package com.ellricky.baselib.adapter.clue

import android.widget.ImageView
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.adapter.SmartViewHolder
import com.andr.common.util.EmptyUtil
import com.andr.common.util.StrUtil
import com.ellricky.baselib.R
import com.ellricky.baselib.entity.new.MyClueData

class ClueAdapter : BaseRecyclerAdapter<MyClueData>(R.layout.base_adapter_my_clue) {
    override fun onBindViewHolder(vh: SmartViewHolder, p1: MyClueData, i: Int) {
        var title = StrUtil.filterEmpty(p1.clue_name)
        val sexName = StrUtil.filterEmpty(p1.clue_sex)
        val age = StrUtil.filterEmpty(p1.clue_age)
        if (!EmptyUtil.isEmpty(sexName)) {
            title += " $sexName"
        }
        if (!EmptyUtil.isEmpty(age)) {
            title += " $age"
        }
        vh.text(R.id.tvTitle, title)
        vh.text(R.id.tvClue, p1.from_name)
        vh.text(R.id.tvPhone, p1.clue_tel)
        vh.text(R.id.tvDate, "录入时间：${p1.clue_input_time}")
        vh.text(R.id.tvInputName, "录入人：" + p1.input_name)
        vh.itemView.findViewById<CardView>(R.id.cvRoot).apply {
            if (p1.return_open == 1) {
                vh.itemView.findViewById<ImageView>(R.id.ivEnd).apply {
                    setImageResource(R.drawable.base_icon_common_list_white)
                }
                //即将回访
                vh.textColorId(R.id.tvTitle, R.color.white)
                    .textColorId(R.id.tvClue, R.color.white)
                    .textColorId(R.id.tvPhone, R.color.white)
                    .textColorId(R.id.tvDate, R.color.white)
                    .textColorId(R.id.tvClueKey, R.color.white)
                    .textColorId(R.id.tvPhoneKey, R.color.white)
                    .textColorId(R.id.tvInputName,R.color.white)
                setCardBackgroundColor(ContextCompat.getColor(context, R.color.blue))
            } else {
                vh.textColorId(R.id.tvTitle, R.color.common_main_black)
                    .textColorId(R.id.tvClue, R.color.common_main_black)
                    .textColorId(R.id.tvPhone, R.color.common_main_black)
                    .textColorId(R.id.tvDate, R.color.common_main_black)
                    .textColorId(R.id.tvClueKey, R.color.common_main_black)
                    .textColorId(R.id.tvPhoneKey, R.color.common_main_black)
                    .textColorId(R.id.tvInputName,R.color.common_main_black)
                setCardBackgroundColor(ContextCompat.getColor(context, R.color.white))
            }
        }
    }
}